﻿using Common;
using MVP;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.Text;
using System.Windows.Forms;

namespace WinForms
{
    public partial class LaporanBulanan : UserControl, ILaporanBulananView
    {
        private LaporanBulananPresenter _presenter;
        public LaporanBulananPresenter GetPresenter()
        {
            return _presenter;
        }

        public LaporanBulanan()
        {
            _presenter = new LaporanBulananPresenter(this);
            InitializeComponent();
        }
        public LaporanBulanan(string bulan, string tahun)
            : this()
        {
            Bulan = bulan;
            Tahun = tahun;
        }

        #region ILaporanBulananView Members

        public DataSet LppbopDataSet
        {
            set
            {
                BindingSource bindingSource = new BindingSource(this.components);
                bindingSource.DataSource = value;
                bindingSource.DataMember = "LaporanBulanan";
                lapBulanDataGridView.DataSource = bindingSource;
                lapBulanBindingNavigator.BindingSource = bindingSource;
            }
            get
            {
                return (DataSet)((BindingSource)lapBulanDataGridView.DataSource).DataSource;
            }
        }

        public string Tahun
        { get; set; }

        public string Bulan
        { get; set; }

        public void SendMessageInfo(string strMessage)
        {
            MessageBox.Show(strMessage, "Information Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        public event EventHandler Save;

        public event EventHandler Initialize;

        #endregion

        private void LaporanBulanan_Load(object sender, EventArgs e)
        {
            Initialize(sender, e);
            lapBulanDataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
            lapBulanDataGridView.ColumnHeadersHeight = lapBulanDataGridView.ColumnHeadersHeight * 4;
            lapBulanDataGridView.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.TopCenter;
            updateToolStripButton.Enabled = false;
            periodeToolStripLabel.Text = String.Format("LAPORAN BULANAN - {0} {1}", Bulan.ToUpper(), Tahun);
            lapBulanDataGridView.AllowUserToAddRows = false;

            lapBulanDataGridView.Columns["Id"].Visible = false;
            lapBulanDataGridView.Columns["Bulan"].Visible = false;
            lapBulanDataGridView.Columns["Tahun"].Visible = false;

            lapBulanDataGridView.Columns[3].HeaderText = "No.";
            lapBulanDataGridView.Columns[3].Width = 30;

            lapBulanDataGridView.Columns[4].HeaderText = "Uraian Penerimaan";
            lapBulanDataGridView.Columns[4].Width = 300;

            lapBulanDataGridView.Columns[5].HeaderText = "Penerimaan - Beban PK";
            lapBulanDataGridView.Columns[5].ReadOnly = true;
            lapBulanDataGridView.Columns[5].Width = 100;
            lapBulanDataGridView.Columns[5].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("id-ID");
            lapBulanDataGridView.Columns[5].DefaultCellStyle.Format = "c";

            lapBulanDataGridView.Columns[6].HeaderText = "Penerimaan - Jumlah";
            lapBulanDataGridView.Columns[6].ReadOnly = true;
            lapBulanDataGridView.Columns[6].Width = 100;
            lapBulanDataGridView.Columns[6].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("id-ID");
            lapBulanDataGridView.Columns[6].DefaultCellStyle.Format = "c";

            lapBulanDataGridView.Columns[7].HeaderText = "Uraian Pengeluaran";
            lapBulanDataGridView.Columns[7].Width = 300;

            lapBulanDataGridView.Columns[8].HeaderText = "Pengeluaran - Beban PK";
            lapBulanDataGridView.Columns[8].ReadOnly = true;
            lapBulanDataGridView.Columns[8].Width = 100;
            lapBulanDataGridView.Columns[8].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("id-ID");
            lapBulanDataGridView.Columns[8].DefaultCellStyle.Format = "c";

            lapBulanDataGridView.Columns[9].HeaderText = "Pengeluaran - Jumlah";
            lapBulanDataGridView.Columns[9].ReadOnly = true;
            lapBulanDataGridView.Columns[9].Width = 100;
            lapBulanDataGridView.Columns[9].DefaultCellStyle.FormatProvider = CultureInfo.GetCultureInfo("id-ID");
            lapBulanDataGridView.Columns[9].DefaultCellStyle.Format = "c";
        }

        private void updateToolStripButton_Click(object sender, EventArgs e)
        {
            ((BindingSource)lapBulanDataGridView.DataSource).EndEdit();
            Save(sender, e);
            updateToolStripButton.Enabled = false;
        }

        private void lapBulanDataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            updateToolStripButton.Enabled = true;
        }

        private void lapBulanDataGridView_Paint(object sender, PaintEventArgs e)
        {

        }

        private void lapBulanDataGridView_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
        {
            e.Column.SortMode = DataGridViewColumnSortMode.NotSortable;
        }
    }
}
